import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { goodsList, setIsShelf, setIsShowShop } from '@apps/ant-bus/src/views/business/goods/goods/api';
import { vipcardList } from '@apps/ant-bus/src/views/business/goods/vipcard/data/api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { h } from 'vue';
import { Switch, Tag } from 'ant-design-vue';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { useMessage } from '@apps/antd-admin/src/hooks/web/useMessage';
import { rules } from '@pkg/utils';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';

export const columns: BasicColumn[] = [
  {
    title: '贵宾厅名称',
    dataIndex: 'goodsName',
    width: 180,
  },
  {
    title: '贵宾厅封面',
    dataIndex: 'coverImg',
    width: 120,
    customRender: render.renderImage,
  },
  {
    title: '营业时间',
    dataIndex: 'roomTime',
    width: 100,
  },
  {
    title: '安检内外',
    dataIndex: 'securityType',
    width: 130,
    customRender: ({ record }: Recordable) => {
      const securityTypes = [
        { label: '安检内', value: '1', color: 'green' },
        { label: '安检外', value: '2', color: 'orange' },
        { label: '航班不同前往不同休息室', value: '3', color: 'blue' },
      ];
      const securityType: any = securityTypes.find(item => item.value == record.securityType);
      if (securityType) {
        return h(Tag, { color: securityType.color }, () => securityType.label);
      }
      return '';
    },
  },
  {
    title: '贵宾厅电话',
    dataIndex: 'roomPhone',
    width: 120,
  },
  {
    title: '市场价格(元)',
    dataIndex: 'goodsPrice',
    width: 100,
  },
  {
    title: '会员价格(元)',
    dataIndex: 'vipPrice',
    width: 100,
  },
  {
    title: '上下架',
    dataIndex: 'isShelf',
    width: 100,
    customRender: ({ record }: Recordable) => {
      if (!Reflect.has(record, 'pendingStatus')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.isShelf,
        checkedValue: 1,
        unCheckedValue: 2,
        checkedChildren: '已上架',
        unCheckedChildren: '已下架',
        loading: record.pendingStatus,
        onChange(checked: number) {
          console.info(checked);
          record.pendingStatus = false;
          const { createMessage } = useMessage();
          setIsShelf(record.viproomId, checked)
            .then(data => {
              record.isShelf = checked;
            })
            .catch(data => {
              console.info('catch', data);
            })
            .finally(() => {
              record.pendingStatus = false;
            });
        },
      });
    },
  },
  {
    title: '商城展示',
    dataIndex: 'isShowShop',
    width: 90,
    customRender: ({ record }: Recordable) => {
      if (!Reflect.has(record, 'pendingStatus')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.isShowShop,
        checkedValue: 1,
        unCheckedValue: 2,
        checkedChildren: '展示',
        unCheckedChildren: '不展示',
        loading: record.pendingStatus,
        onChange(checked: number) {
          record.pendingStatus = false;
          const { createMessage } = useMessage();
          setIsShowShop(record.viproomId, checked)
            .then(data => {
              record.isShowShop = checked;
            })
            .catch(data => {
              console.info('catch', data);
            })
            .finally(() => {
              record.pendingStatus = false;
            });
        },
      });
    },
  },
  {
    title: '包含通道',
    dataIndex: 'iscontain',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const iscontain = record.iscontain;
      const color = iscontain == 1 ? 'green' : 'orange';
      const text = iscontain == 1 ? '包含' : '不包含';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '需要预约',
    dataIndex: 'isAppoint',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const isAppoint = record.isAppoint;
      const color = isAppoint == 1 ? 'green' : 'red';
      const text = isAppoint == 1 ? '不需要' : '需要';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '预约控制(天)',
    dataIndex: 'maxTime',
    width: 100,
  },
  {
    title: '贵宾厅地址',
    dataIndex: 'roomAddress',
    width: 200,
  },
  {
    title: '儿童规定',
    dataIndex: 'childrensRule',
    width: 120,
  },
  {
    title: '可带人',
    dataIndex: 'isTakePeople',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const isTakePeople = record.isTakePeople;
      const color = isTakePeople == 1 ? 'green' : 'red';
      const text = isTakePeople == 1 ? '可以' : '不可以';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '有效期(天)',
    dataIndex: 'validDay',
    width: 100,
  },
  {
    title: '排序',
    dataIndex: 'viproomSort',
    width: 100,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'goodsName',
    label: '贵宾厅名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'isShelf',
    label: '是否上架',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '上架', value: 1 },
        { label: '下架', value: 2 },
      ],
    },
  },
  {
    field: 'isIntegral',
    label: '是否兑换',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '支持兑换', value: 1 },
        { label: '不支持兑换', value: 2 },
      ],
    },
  },
  {
    field: 'isTakePeople',
    label: '带人设置',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '不可以', value: 2 },
        { label: '可以', value: 1 },
      ],
    },
  },
  {
    field: 'weChatId',
    label: '上架公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    field: 'isAppoint',
    label: '需要预约',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '不需要', value: 1 },
        { label: '需要', value: 2 },
      ],
    },
  },
  {
    field: 'checkEmployeeId',
    label: '所属负责人',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: employeeList,
      params: {
        handlerName: 'busEmployeeListHandler',
        employeeType: 'platform',
        employeePosition: 'manager',
      },
      labelField: 'employeeAccountName',
      valueField: 'employeeId',
      showSearch: true,
      immediate: false,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'divider1',
    label: '贵宾厅基础信息',
    component: 'Divider',
    helpMessage: '贵宾厅基础信息',
  },
  {
    label: '贵宾厅Id',
    field: 'viproomId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '厅类型',
    field: 'viproomType',
    component: 'Select',
    required: true,
    show: false,
    componentProps: {
      options: [
        { label: '机场贵宾厅', value: 1 },
        { label: '高铁贵宾厅', value: 2 },
      ],
    },
  },
  {
    label: '所属机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: false,
    show: false,
    ifShow: ({ model }) => {
      if (model.viproomType == 1) {
        return true;
      } else {
        return false;
      }
    },
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '高铁Id',
    field: 'highSpeedTrainId',
    component: 'Input',
    required: false,
    show: false,
    ifShow: ({ model }) => {
      if (model.viproomType == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '贵宾厅Id',
    field: 'viproomId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '厅名称',
    field: 'goodsName',
    component: 'Input',
    required: true,
  },
  {
    label: '营业时间',
    field: 'roomTime',
    component: 'Input',
    required: true,
  },
  {
    label: '安检内外',
    field: 'securityType',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '安检内', value: 1 },
        { label: '安检外', value: 2 },
        { label: '航班不同前往不同休息室', value: 3 },
      ],
    },
  },
  {
    label: '厅电话',
    field: 'roomPhone',
    component: 'Input',
  },
  {
    label: '市场价格',
    field: 'goodsPrice',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
  },
  {
    label: '会员价格',
    field: 'vipPrice',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
  },
  {
    label: '成本价格',
    field: 'costPrice',
    component: 'InputNumber',
    required: false,
  },
  {
    label: '销量',
    field: 'sales',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '库存',
    field: 'inventory',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '排序',
    field: 'viproomSort',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '厅地址',
    field: 'roomAddress',
    component: 'Input',
    required: true,
  },
  {
    label: '航站楼标签',
    field: 'tagTerminal',
    component: 'Input',
    required: false,
  },
  {
    label: '商城展示',
    field: 'isShowShop',
    component: 'Select',
    defaultValue: 2,
    required: true,
    componentProps: {
      options: [
        { label: '不展示', value: 2 },
        { label: '展示', value: 1 },
      ],
    },
  },
  {
    label: '扫码说明',
    field: 'useDesc',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '封面图',
    field: 'coverImg',
    component: 'ImageUpload',
    required: false,
  },
  {
    label: '轮播图',
    field: 'goodsImg',
    component: 'ImageUpload',
    required: false,
    componentProps: {
      fileMax: 5,
    },
  },
  {
    label: '厅简介',
    field: 'goodsDesc',
    component: 'TyEditor',
  },
  {
    field: 'divider2',
    label: '合作企业贵宾厅信息',
    component: 'Divider',
    helpMessage: '合作企业贵宾厅信息',
  },
  {
    label: '营业起时间',
    field: 'startTime',
    component: 'Input',
    required: false,
    componentProps: {
      placeholder: '有明确营业时间的就返回"09:00-21:00"格式;无明确营业时间的可返回“最早航班-最晚航班”格式',
    },
  },
  {
    label: '营业止时间',
    field: 'endTime',
    component: 'Input',
    required: false,
    componentProps: {
      placeholder: '有明确营业时间的就返回"09:00-21:00"格式;无明确营业时间的可返回“最早航班-最晚航班”格式',
    },
  },
  {
    label: '起止时间提示',
    field: 'startEndTimeTip',
    slot: 'startEndTimeTip',
    component: 'Input',
  },
  {
    label: '出发类型',
    field: 'departType',
    component: 'Select',
    required: false,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '国内出发', value: 1 },
        { label: '国外出发', value: 2 },
      ],
    },
  },
  {
    label: '使用时长',
    field: 'canUseHours',
    component: 'InputNumber',
    defaultValue: 2,
    required: false,
  },
  {
    label: '厅类型',
    field: 'viproomCategory',
    component: 'Select',
    required: false,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '贵宾厅', value: 1 },
        { label: '餐食', value: 2 },
      ],
    },
  },
  {
    label: '航站楼信息',
    field: 'terminalInfo',
    component: 'Input',
    required: false,
  },
  {
    field: 'divider3',
    label: '贵宾厅设置',
    component: 'Divider',
    helpMessage: '贵宾厅设置',
  },
  {
    label: '所属负责人',
    field: 'checkEmployeeId',
    component: 'ApiSelect',
    required: false,
    componentProps: ({ formModel }) => {
      return {
        api: employeeList,
        params: {
          handlerName: 'busEmployeeListHandler',
          employeeType: 'platform',
          employeePosition: 'manager',
        },
        labelField: 'employeeAccountName',
        valueField: 'employeeId',
        showSearch: true,
        immediate: true,
        onChange: employeeId => {
          formModel.serverId = null;
        },
      };
    },
  },
  {
    label: '是否上架',
    field: 'isShelf',
    component: 'Select',
    required: true,
    defaultValue: 2,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '不上架', value: 2 },
        { label: '上架', value: 1 },
      ],
    },
  },
  {
    label: '推荐卡种',
    field: 'vipcardId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: false,
      showSearch: true,
    },
  },
  {
    label: '含有通道',
    field: 'iscontain',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '不含有', value: 2 },
        { label: '含有', value: 1 },
      ],
    },
  },
  {
    label: '贵宾通道',
    field: 'viponlyId',
    component: 'ApiSelect',
    required: false,
    componentProps: () => {
      return {
        api: goodsList,
        params: { handlerName: 'busGoodsListHandler', categoryCode: 'viponly' },
        labelField: 'goodsName',
        valueField: 'goodsId',
        immediate: true,
        showSearch: true,
      };
    },
  },
  {
    label: '通道名称',
    field: 'viponlyName',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      if (model.iscontain == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '需要预约',
    field: 'isAppoint',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '需要', value: 2 },
        { label: '不需要', value: 1 },
      ],
    },
  },
  {
    label: '预约控制(天)',
    field: 'maxTime',
    component: 'InputNumber',
    required: true,
    ifShow: ({ model }) => {
      if (model.isAppoint == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '预约开始时间',
    field: 'appointmentStartTime',
    component: 'TimePicker',
    required: true,
    componentProps: {
      valueFormat: 'HH:mm',
      format: 'HH:mm',
    },
    ifShow: ({ model }) => {
      if (model.isAppoint == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '预约结束时间',
    field: 'appointmentEndTime',
    component: 'TimePicker',
    required: true,
    componentProps: {
      valueFormat: 'HH:mm',
      format: 'HH:mm',
    },
    ifShow: ({ model }) => {
      if (model.isAppoint == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '有效期',
    field: 'isHaveValidDay',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '无有效期', value: 2 },
        { label: '有有效期', value: 1 },
      ],
    },
  },
  {
    label: '有效期(天)',
    field: 'validDay',
    component: 'InputNumber',
    required: true,
    defaultValue: 60,
    ifShow: ({ model }) => {
      if (model.isHaveValidDay == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '儿童规定',
    field: 'childrensRule',
    component: 'Input',
    required: false,
  },
  {
    label: '带人设置',
    field: 'isTakePeople',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '不可以', value: 2 },
        { label: '可以', value: 1 },
      ],
    },
  },
  {
    field: 'divider4',
    label: '代理商售卖信息设置',
    component: 'Divider',
    helpMessage: '代理商售卖信息设置',
  },
  {
    label: '代理商价格',
    field: 'agentPrice',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
  },
  {
    label: '上架到代理商',
    field: 'isShelfAgent',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '不上架', value: 2 },
        { label: '上架', value: 1 },
      ],
    },
  },
  {
    field: 'divider5',
    label: '电子金兑换设置',
    component: 'Divider',
    helpMessage: '电子金兑换设置',
  },
  {
    label: '是否支持电子金兑换',
    field: 'isIntegral',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '支持', value: 1 },
        { label: '不支持', value: 2 },
      ],
    },
  },
  {
    label: '所需电子金(整数)',
    field: 'integralValue',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
  },
];
